package com.nkzy.mapper;

import com.nkzy.pojo.Article;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleMapper {

    // 查询所有文章
    @Select("SELECT * FROM article")
    List<Article> findAll();

    // 根据ID查询文章
    @Select("SELECT * FROM article WHERE id = #{id}")
    Article findById(Integer id);

    // 新增文章
    @Insert("INSERT INTO article (title, content, cover_img, state, category_id, create_user, create_time, update_time) " +
            "VALUES (#{title}, #{content}, #{coverImg}, #{state}, #{categoryId}, #{createUser}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Article article);

    // 更新文章
    @Update("UPDATE article SET title = #{title}, content = #{content}, cover_img = #{coverImg}, state = #{state}, " +
            "category_id = #{categoryId}, create_user = #{createUser}, update_time = #{updateTime} WHERE id = #{id}")
    int update(Article article);

    // 删除文章
    @Delete("DELETE FROM article WHERE id = #{id}")
    int delete(Integer id);
}